package com.example.wechat.mapper;

import java.util.List;
import java.util.Optional;

import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.example.wechat.model.WechatUnreadMessage;

/**
 * 用户未读消息统计Mapper接口
 * 
 * @author ruoyi
 * @date 2025-11-12
 */
public interface WechatUnreadMessageMapper {

    @Select("select * from t_wechat_unread_messages where user_id = ${userId} and conversation_id = ${conversationId}")
    public Optional<WechatUnreadMessage> findByUserIdAndConversationId(Long userId, Long conversationId);

    @Update("update t_wechat_unread_messages set unread_count = #{unreadCount}, last_message_id = #{lastMessageId}, "
            + "update_time = #{updateTime} where id = #{id}")
    public int save(WechatUnreadMessage wechatUnreadMessage);

    @Select("select sum(unread_count) from t_wechat_unread_messages where user_id = #{userId}")
    public int sumUnreadCountByUserId(String userId);
}
